/**
 * Created by HuQiang on 2017/8/4.
 */
import React from 'react';
import 'antd/dist/antd.css';  // or 'antd/dist/antd.less'
import {Select, Button, Input, Modal} from 'antd';
require("./Home.css");
require("./PersonDetail.css");
import $ from "jquery";
const Option = Select.Option;
const {TextArea} = Input;

export default class PersonDetail extends React.Component {
    constructor(props) {
        super(props);
        const userSessionStorage = JSON.parse(window.sessionStorage.getItem("userStorage"));
        if (userSessionStorage !== null) {
            this.state = {
                img: userSessionStorage.data.image,
                id: userSessionStorage.data.id,
                others: userSessionStorage.data.others,
                profession: userSessionStorage.data.profession,
                disable: true
            }
        }
    }

    handleSubmit = (e) => {
        e.preventDefault();
        if (this.state.others === "") {
            Modal.error({
                title: '温馨提示',
                content: "简历不能为空哦"
            });
            return;
        }
        this.setState({
            disable: true
        });
        $.ajax({
            type: "POST",
            url: "http://123.207.214.129:9090/LanOu/updateBasic",
            data: {
                id: this.state.id,
                profession: this.state.profession,
                others: this.state.others
            },
            dataType: "json",
            success: (data) => {
                if (data.msg === "成功") {
                    Modal.success({
                        title: '温馨提示',
                        content: "修改成功"
                    });

                }
                console.log(data);
            },
            error: function (e) {
                console.log(e);
            }
        });
    };

    render() {
        return (
            <div>
                <div className="title-person">
                    <p>个人信息</p>
                </div>
                <div className="body-person">
                    <img src={this.state.img}/>
                    <p>
                        账号:&nbsp;&nbsp;{this.state.id}
                    </p>
                    <p>
                        职业:&nbsp;&nbsp;
                        <Select style={selectStyle} labelInValue defaultValue={{key: this.state.profession}}
                                disabled={this.state.disable}
                                onChange={(e) => {
                                    this.setState({
                                        profession: e.label
                                    })
                                }}>
                            <Option value="Java工程师">Java工程师</Option>
                            <Option value="web前端工程师">web前端工程师</Option>
                        </Select>
                    </p>
                    <p>
                        简历:&nbsp;&nbsp;<br/>
                        <TextArea style={textStyle} rows={4} defaultValue={this.state.others} onChange={(e) => {
                            this.setState({others: e.target.value})
                        }} disabled={this.state.disable}/>
                    </p>

                    <Button style={setStyle} type="default" onClick={() => {
                        this.setState({disable: false})
                    }}>编辑信息</Button>

                    <form onSubmit={(e) => {
                        this.handleSubmit(e)
                    }}>
                        <Button style={submitStyle} type="default" htmlType="submit">
                            完成
                        </Button>
                    </form>
                </div>
            </div>
        );
    }
}
const selectStyle = {
    width: '7rem',
};
const setStyle = {
    width: '7rem',
    marginTop: '0.5rem'
};
const submitStyle = {
    width: '7rem',
    background: '#0d79d1',
    color: '#fff',
    marginTop: '0.5rem'
};
const textStyle = {
    width: '30rem',
};


